# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: pymongo删除相同内容保留一条.py
@time: 2021/8/23 12:39
'''
import pymongo
from icecream import ic

client = pymongo.MongoClient()
db = client['python']['jaoben']

def find_db(data):
    filter = {}
    keyword = data
    filter["标题"] = keyword
    res = db.find_one(filter)
    db.remove(filter)
    db.insert_one(res)
    ic(res['标题'] + '==================去重完成')


data = db.find()
for i in range(data.count()):
    # ic(data[i]['标题'])
    d = data[i]['标题']
    # find_db(d)
    ic(d)
ic(db.find().count())




